package com.huqing.icu.controller.app;

import com.huqing.icu.base.BaseController;
import com.huqing.icu.base.PageDto;
import com.huqing.icu.inout.in.app.UserFavoriteHouseReq;
import com.huqing.icu.inout.in.app.UserLikeHouseReq;
import com.huqing.icu.service.UserHouseRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户端房源接口
 *
 * @author huqing
 * @date 2024-09-15 23:16:21
 */

@RestController
@RequestMapping("/api/user_action")
@Tag(name = "用户对房源的行为接口")
public class UserHouseActionController extends BaseController {

    @Resource
    private UserHouseRelationService userHouseRelationService;

    @Operation(summary = "喜欢房子")
    @RequestMapping(value = "/like", method = RequestMethod.POST, produces = "application/json")
    public String like(HttpServletRequest request, @RequestBody UserLikeHouseReq userLikeHouseReq) {
        //Long userId = checkAndGetUserId(request);
        Long userId = 9600L;
        userLikeHouseReq.setUserId(userId);
        return jsonSuccessForNull(userHouseRelationService.likeHouse(userLikeHouseReq));
    }

    @Operation(summary = "收藏房子")
    @RequestMapping(value = "/favorite", method = RequestMethod.POST, produces = "application/json")
    public String favorite(HttpServletRequest request, @RequestBody UserFavoriteHouseReq userFavoriteHouseReq) {
        //Long userId = checkAndGetUserId(request);
        Long userId = 9600L;
        userFavoriteHouseReq.setUserId(userId);
        return jsonSuccessForNull(userHouseRelationService.favoriteHouse(userFavoriteHouseReq));
    }

    @Operation(summary = "查询我点赞的房源列表")
    @RequestMapping(value = "/query_my_like", method = RequestMethod.POST, produces = "application/json")
    public String queryMyLike(@RequestBody PageDto pageDto, HttpServletRequest request) {
        //Long userId = getLoginUserId(request);
        Long userId = 9600L;
        return jsonSuccessForNull(userHouseRelationService.queryMyLike(pageDto, userId));
    }

    @Operation(summary = "查询我点赞的房源列表")
    @RequestMapping(value = "/query_my_favorite", method = RequestMethod.POST, produces = "application/json")
    public String queryMyFavorite(@RequestBody PageDto pageDto, HttpServletRequest request) {
        //Long userId = getLoginUserId(request);
        Long userId = 9600L;
        return jsonSuccessForNull(userHouseRelationService.queryMyFavorite(pageDto, userId));
    }

}
